//
//  SliderDemo.swift
//  SwiftUIDemo
//
//  Created by Tilt Wang on 2025/7/1.
//

import SwiftUI

struct SliderDemo: View {
    
    @State var sliderValue: Double = 10
    @State var color: Color = .red
    
    var body: some View {
        VStack {
            Text("value: \(String(format: "%.0f", sliderValue))")
                .foregroundColor(color)
            Slider(value: $sliderValue)
            Slider(value: $sliderValue, in: 1...5, step: 1.0)
            Slider(
                value: $sliderValue,
                in: 1...5,
                label: {
                    Text("title")
                },
                minimumValueLabel: {
                    Text("1")
                        .font(.largeTitle)
                        .foregroundColor(.orange)
                },
                maximumValueLabel: {
                    Text("5")
                }, onEditingChanged: { _ in
                    color = .green
                })
                .accentColor(.red)
        }
    }
}

#Preview {
    SliderDemo()
}
